home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / TUT1-9.ZIP / TUT2.TXT < prev    next >
Text File  |  1993-07-07  |  12KB  |  283 lines

  1.                    ╒═══════════════════════════════╕
  2.                    │         W E L C O M E         │
  3.                    │  To the VGA Trainer Program   │ │
  4.                    │              By               │ │
  5.                    │      DENTHOR of ASPHYXIA      │ │ │
  6.                    ╘═══════════════════════════════╛ │ │
  7.                      ────────────────────────────────┘ │
  8.                        ────────────────────────────────┘
  9.  
  10.                            --==[ PART 2 ]==--
  11.  
  12.  
  13.  
  14. ■ Introduction
  15.  
  16.  
  17.  
  18. Hi there again! This is Grant Smith, AKA Denthor of ASPHYXIA. This is the
  19. second part of my Training Program for new programmers. I have only had a
  20. lukewarm response to my first part of the trainer series ... remember, if
  21. I don't hear from you, I will assume that you are all dead and will stop
  22. writing the series ;-). Also, if you do get in contact with me I will give
  23. you some of our fast assembly routines which will speed up your demos no
  24. end. So go on, leave mail to GRANT SMITH in the main section of the
  25. MailBox BBS, start up a discussion or ask a few questions in this Conference,
  26. leave mail to ASPHYXIA on the ASPHYXIA BBS, leave mail to Denthor on
  27. Connectix, or write to Grant Smith,
  28.                        P.O.Box 270
  29.                        Kloof
  30.                        3640
  31. See, there are many ways you can get in contact with me! Use one of them!
  32.  
  33. In this part, I will put the Pallette through it's paces. What the hell is
  34. a pallette? How do I find out what it is? How do I set it? How do I stop
  35. the "fuzz" that appears on the screen when I change the pallette? How do
  36. I black out the screen using the pallette? How do I fade in a screen?
  37. How do I fade out a screen? Why are telephone calls so expensive?
  38. Most of these quesions will be answered in this, the second part of my
  39. Trainer Series for Pascal.
  40.  
  41.  
  42. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  43. ■  What is the Pallette?
  44.  
  45. A few weeks ago a friend of mine was playing a computer game. In the game
  46. there was a machine with stripes of blue running across it. When the
  47. machine was activated, while half of the the blue stripes stayed the same,
  48. the other half started to change color and glow. He asked me how two stripes
  49. of the same color suddenly become different like that. The answer is simple:
  50. the program was changing the pallette. As you know from Part 1, there are
  51. 256 colors in MCGA mode, numbered 0 to 255. What you don't know is that each
  52. if those colors is made up of different intensities of Red, Green and Blue,
  53. the primary colors (you should have learned about the primary colors at
  54. school). These intensities are numbers between 0 and 63. The color of
  55. bright red would for example be obtained by setting red intensity to 63,
  56. green intensity to 0, and blue intensity to 0. This means that two colors
  57. can look exactly the same, eg you can set color 10 to bright red and color
  58. 78 to color bright red. If you draw a picture using both of those colors,
  59. no-one will be able to tell the difference between the two.. It is only
  60. when you again change the pallette of either of them will they be able to
  61. tell the difference. Also, by changing the whole pallette, you can obtain
  62. the "Fade in" and "Fade out" effects found in many demos and games.
  63. Pallette manipulation can become quite confusing to some people, because
  64. colors that look the same are in fact totally seperate.
  65.  
  66.  
  67. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  68. ■  How do I read in the pallette value of a color?
  69.  
  70. This is very easy to do. To read in the pallette value, you enter in the
  71. number of the color you want into port $3c7, then read in the values of
  72. red, green and blue respectively from port $3c9. Simple, huh? Here is a
  73. procedure that does it for you :
  74.  
  75. Procedure GetPal(ColorNo : Byte; Var R,G,B : Byte);
  76.   { This reads the values of the Red, Green and Blue values of a certain
  77.     color and returns them to you. }
  78. Begin
  79.    Port[$3c7] := ColorNo;
  80.    R := Port[$3c9];
  81.    G := Port[$3c9];
  82.    B := Port[$3c9];
  83. End;
  84.  
  85. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  86. ■  How do I set the pallette value of a color?
  87.  
  88. This is also as easy as 3.1415926535897932385. What you do is you enter in
  89. the number of the color you want to change into port $3c8, then enter the
  90. values of red, green and blue respectively into port $3c9. Because you are
  91. all so lazy I have written the procedure for you ;-)
  92.  
  93.  
  94. Procedure Pal(ColorNo : Byte; R,G,B : Byte);
  95.   { This sets the Red, Green and Blue values of a certain color }
  96. Begin
  97.    Port[$3c8] := ColorNo;
  98.    Port[$3c9] := R;
  99.    Port[$3c9] := G;
  100.    Port[$3c9] := B;
  101. End;
  102.  
  103.  
  104. Asphyxia doesn't use the above pallete procedures, we use assembler versions,
  105. which will be given to PEOPLE WHO RESPOND TO THIS TRAINER SERIES (HINT,
  106. HINT)
  107.  
  108.  
  109. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  110. ■  How do I stop the "fuzz" that appears on my screen when I change the
  111.         pallette?
  112.  
  113. If you have used the pallette before, you will have noticed that there is
  114. quite a bit of "fuzz" on the screen when you change it. The way we counter
  115. this is as follows : There is an elctron beam on your monitor that is
  116. constantly updating your screen from top to bottom. As it gets to the
  117. bottom of the screen, it takes a while for it to get back up to the top of
  118. the screen to start updating the screen again. The period where it moves
  119. from the bottom to the top is called the Verticle Retrace. During the
  120. verticle retrace you may change the pallette without affecting what is
  121. on the screen. What we do is that we wait until a verticle retrace has
  122. started by calling a certain procedure; this means that everything we do
  123. now will only be shown after the verticle retrace, so we can do all sorts
  124. of strange and unusual things to the screen during this retrace and only
  125. the results will be shown when the retrace is finished. This is way cool,
  126. as it means that when we change the pallette, the fuzz doesn't appear on
  127. the screen, only the result (the changed pallette), is seen after the
  128. retrace! Neat, huh? ;-) I have put the purely assembler WaitRetrace routine
  129. in the sample code that follows this message. Use it wisely, my son.
  130.  
  131. NOTE : WaitRetrace can be a great help to your coding ... code that fits
  132.        into one retrace will mean that the demo will run at the same
  133.        speed no matter what your computer speed (unless you are doing a lot
  134.        during the WaitRetrace and the computer is slooooow). Note that in
  135.        the following sample program and in our SilkyDemo, the thing will run
  136.        at the same speed whether turbo is on or off.
  137.  
  138.  
  139. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  140. ■  How do I black out the screen using the pallette?
  141.  
  142. This is basic : just set the Red, Green and Blue values of all colors to
  143. zero intensity, like so :
  144.  
  145. Procedure Blackout;
  146.   { This procedure blackens the screen by setting the pallette values of
  147.     all the colors to zero. }
  148. VAR loop1:integer;
  149. BEGIN
  150.   WaitRetrace;
  151.   For loop1:=0 to 255 do
  152.     Pal (loop1,0,0,0);
  153. END;
  154.  
  155.  
  156. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  157. ■  How do I fade in a screen?
  158.  
  159. Okay, this can be VERY effective. What you must first do is grab the
  160. pallette into a variable, like so :
  161.  
  162.    VAR Pall := Array [0.255,1..3] of BYTE;
  163.  
  164. 0 to 255 is for the 256 colors in MCGA mode, 1 to 3 is red, green and blue
  165. intensity values;
  166.  
  167. Procedure GrabPallette;
  168. VAR loop1:integer;
  169. BEGIN
  170.   For loop1:=0 to 255 do
  171.     Getpal (loop1,pall[loop1,1],pall[loop1,2],pall[loop1,3]);
  172. END;
  173.  
  174. This loads the entire pallette into variable pall. Then you must blackout
  175. the screen (see above), and draw what you want to screen without the
  176. construction being shown. Then what you do is go throgh the pallette. For
  177. each color, you see if the individual intensities are what they should be.
  178. If not, you increase them by one unit until they are. Beacuse intensites
  179. are in a range from 0 to 63, you only need do this a maximum of 64 times.
  180.  
  181. Procedure Fadeup;
  182. VAR loop1,loop2:integer;
  183.     Tmp : Array [1..3] of byte;
  184.       { This is temporary storage for the values of a color }
  185. BEGIN
  186.   For loop1:=1 to 64 do BEGIN
  187.       { A color value for Red, green or blue is 0 to 63, so this loop only
  188.         need be executed a maximum of 64 times }
  189.     WaitRetrace;
  190.     For loop2:=0 to 255 do BEGIN
  191.       Getpal (loop2,Tmp[1],Tmp[2],Tmp[3]);
  192.       If Tmp[1]<Pall[loop2,1] then inc (Tmp[1]);
  193.       If Tmp[2]<Pall[loop2,2] then inc (Tmp[2]);
  194.       If Tmp[3]<Pall[loop2,3] then inc (Tmp[3]);
  195.         { If the Red, Green or Blue values of color loop2 are less then they
  196.           should be, increase them by one. }
  197.       Pal (loop2,Tmp[1],Tmp[2],Tmp[3]);
  198.         { Set the new, altered pallette color. }
  199.     END;
  200.   END;
  201. END;
  202.  
  203. Hey-presto! The screen fades up. You can just add in a delay before the
  204. waitretrace if you feel it is too fast. Cool, no?
  205.  
  206.  
  207. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  208. ■  How do I fade out a screen?
  209.  
  210. This is just like the fade in of a screen, just in the opposite direction.
  211. What you do is you check each color intensity. If it is not yet zero, you
  212. decrease it by one until it is. BAAASIIIC!
  213.  
  214. Procedure FadeDown;
  215. VAR loop1,loop2:integer;
  216.     Tmp : Array [1..3] of byte;
  217.       { This is temporary storage for the values of a color }
  218. BEGIN
  219.   For loop1:=1 to 64 do BEGIN
  220.     WaitRetrace;
  221.     For loop2:=0 to 255 do BEGIN
  222.       Getpal (loop2,Tmp[1],Tmp[2],Tmp[3]);
  223.       If Tmp[1]>0 then dec (Tmp[1]);
  224.       If Tmp[2]>0 then dec (Tmp[2]);
  225.       If Tmp[3]>0 then dec (Tmp[3]);
  226.         { If the Red, Green or Blue values of color loop2 are not yet zero,
  227.           then, decrease them by one. }
  228.       Pal (loop2,Tmp[1],Tmp[2],Tmp[3]);
  229.         { Set the new, altered pallette color. }
  230.     END;
  231.   END;
  232. END;
  233.  
  234. Again, to slow the above down, put in a delay above the WaitRetrace. Fading
  235. out the screen looks SO much more impressive then just clearing the screen;
  236. it can make a world of difference in the impression your demo etc will
  237. leave on the people viewing it. To restore the pallette, just do this :
  238.  
  239. Procedure RestorePallette;
  240. VAR loop1:integer;
  241. BEGIN
  242.   WaitRetrace;
  243.   For loop1:=0 to 255 do
  244.     pal (loop1,Pall[loop1,1],Pall[loop1,2],Pall[loop1,3]);
  245. END;
  246.  
  247.  
  248. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  249. ■  In closing
  250.  
  251. Well, there are most of those origional questions answered ;-) The following
  252. sample program is quite big, so it might take you a while to get around it.
  253. Persevere and thou shalt overcome. Pallette manipulation has been a thorn
  254. in many coders sides for quite some time, yet hopefully I have shown you
  255. all how amazingly simple it is once you have grasped the basics.
  256.  
  257. I need more feedback! In which direction would you like me to head? Is there
  258. any particular section you would like more info on? Also, upload me your
  259. demo's, however trivial they might seem. We really want to get in contact
  260. with/help out new and old coders alike, but you have to leave us that message
  261. telling us about yourself and what you have done or want to do.
  262.  
  263. IS THERE ANYBODY OUT THERE!?!
  264.  
  265. P.S. Our new demo should be out soon ... it is going to be GOOOD ... keep
  266.      an eye out for it.
  267.  
  268.           [ And so she came across him, slumped over his keyboard
  269.             yet again . 'It's three in the morning' she whispered.
  270.             'Let's get you to bed'. He stirred, his face bathed in
  271.             the dull light of his monitor. He mutters something.
  272.             As she leans across him to disconnect the power, she
  273.             asks him; 'Was it worth it?'. His answer surprises her.
  274.             'No.' he says. In his caffiene-enduced haze, he smiles.
  275.             'But it sure is a great way to relax.'                  ]
  276.                                            - Grant Smith
  277.                                               Tue 13 July, 1993
  278.                                                2:23 am.
  279.  
  280. See you next week!
  281.    - Denthor
  282.  
  283.